package com.txx.app.play.module.download.contract;

import android.text.TextUtils;

import com.orhanobut.logger.Logger;
import com.txx.app.play.Constant;
import com.txx.app.play.PlayApp;
import com.txx.app.play.commom.net.HttpUtil;
import com.txx.app.play.commom.net.HttpUtilsService;
import com.txx.app.play.commom.util.MyLog;
import com.txx.app.play.module.live.bean.ClearRecordBean;

import java.util.HashMap;
import java.util.Map;

import rx.Subscriber;

/**
 * Created by houyongliang on 2018/2/2.
 */

public class DowningFragmentPresenter extends IDowningFragmentContract.IDowningFragmentPresenter {

       public DowningFragmentPresenter() {
        this.mModel = new DowningFragmentModel();/*获取 m 层对象*/
    }

    @Override
    public void onStart() {

    }


    @Override
    void httpRequestData(int page, int size) {
        Map<String, String> params = new HashMap<>();
        params.put("staffNumber", TextUtils.isEmpty(PlayApp.USER_STAFF_BUILDER) ? "" : PlayApp.USER_STAFF_BUILDER);
        if (mView != null) {
            mView.showDialog();
        }
        HttpUtil.init(HttpUtilsService.getLiveService().geClearRecordBean(params, TextUtils.isEmpty(PlayApp.TOKEN) ? "" : PlayApp.TOKEN), new Subscriber<ClearRecordBean>() {
            @Override
            public void onCompleted() {
                MyLog.wtf("zcc", "观看记录清除请求成功");
            }

            @Override
            public void onError(Throwable e) {
                if (mView != null) {
                    mView.dissmissDialog();
                }
                Logger.e("观看记录清除请求失败" + e.getMessage());
            }

            @Override
            public void onNext(ClearRecordBean clearRecordBean) {
                if (mView == null) {
                    return;
                }
                mView.dissmissDialog();
                MyLog.wtf("zcc", "点播清空请求成功liveBean" + clearRecordBean.toString());
                if (TextUtils.isEmpty(clearRecordBean.getCode())) {
                    switch (clearRecordBean.getRspCode()) {
                        case Constant.LOGOUT100:
                        case Constant.LOGOUT200:
                        case Constant.LOGOUT300:
                            mView.showErrorDialog(clearRecordBean.getRspDesc());
                            break;
                    }
                } else {
                    switch (clearRecordBean.getCode()) {
                        case Constant.GET_DATA_SUCCESS:
                          // mView.clearRecordData();
                            break;
                        case Constant.GET_DATA_FAIL:
                            mView.showErrorDialog(clearRecordBean.getMessage());
                            break;
                    }
                }


            }
        });
    }
}
